package com.yunbiao.ybbusstopplate.serialport.agreement

import com.yunbiao.ybbusstopplate.serialport.SerialPortConfig
import com.yunbiao.ybbusstopplate.refactoring.ui.yibin.ZHXPortAgreement
import tp.xmaihh.serialport.SerialHelper

class AgreementTool {
    companion object{
        private val TAG="AgreementTool"
        fun analysisData(serialHelper: SerialHelper?,bytes:ByteArray,iAgreementListener: IAgreementListener?){
            val portType = SerialPortConfig.PORT_TYPE
//            Log.d(TAG,"portType---------->"+portType)
            when(portType){
                SerialPortConfig.TYPE_TD->{//通达
                    TDPortAgreement.getInstance()!!.setAgreementListener(iAgreementListener)
                    TDPortAgreement.getInstance()!!.analysisData(bytes)
                    return
                }
                SerialPortConfig.TYPE_TD2020->{
                    TD2020PortAgreement.getInstance()!!.setAgreementListener(iAgreementListener)
                    TD2020PortAgreement.getInstance()!!.analysisData(bytes)
                }
                SerialPortConfig.TYPE_TK->{//通卡
                    TKPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    TKPortAgreement.getInstance().analysisData(bytes)
                    return
                }
                SerialPortConfig.TYPE_HY->{
                    HYPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    HYPortAgreement.getInstance().anilzData(bytes)
                    return
                }
                SerialPortConfig.TYPE_LS->{
                    LSPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    LSPortAgreement.getInstance().anlzData(bytes)
                    return
                }
                SerialPortConfig.TYPE_LSTK->{
                    LSTKPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    LSTKPortAgreement.getInstance().analyzeData(bytes)
                }
                SerialPortConfig.TYPE_HX->{
                    HXPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    HXPortAgreement.getInstance().anlzData(bytes)
                }
                SerialPortConfig.TYPE_TM->{
                    TMPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    TMPortAgreement.getInstance().anlzData(serialHelper,bytes)
                }
                SerialPortConfig.TYPE_LTY->{
                    LTYPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    LTYPortAgreement.getInstance().anlzData(serialHelper,bytes)
                }
                SerialPortConfig.TYPE_ZHX->{
                    ZHXPortAgreement.getInstance().setAgreementListener(iAgreementListener)
                    ZHXPortAgreement.getInstance().anlzData(serialHelper,bytes)
                }
                else->{
                    if (iAgreementListener != null) {
                        iAgreementListener.agreementFailed()
                    }
                }
            }
        }
    }
}